import React from 'react';
import regs from '@/utils/regs';
import CommonPage from '@/components/page/CommonPage';
const daoName = 'Organization';
const columns: API.Column[] = [
  {
    title: '部门编号',
    dataIndex: 'No',
    key: 'No',
    width: 120,
    sorter: true,
    dispaly: true,
    filter: true,
  },
  {
    title: '部门名称',
    width: 150,
    sorter: true,
    dataIndex: 'Name',
    key: 'Name',
    dispaly: true,
    filter: true,
  },
  {
    title: '所属部门',
    width: 150,
    sorter: true,
    key: 'ParentID',
    dataIndex: ['Parent', 'Name'],
    dispaly: true,
    filter: true,
  },
  {
    title: '部门类型',
    width: 150,
    sorter: true,
    key: 'TypeID',
    dataIndex: ['Type', 'Name'],
    dispaly: true,
    filter: true,
  },
  {
    title: '顺序号',
    width: 100,
    sorter: true,
    dataIndex: 'OrderNo',
    key: 'OrderNo',
    dispaly: true,
    filter: true,
  },
];
const controls: API.Control[] = [
  {
    name: 'No',
    type: 'text',
    label: '部门编号',
    grid: 12 / 24,
    rules: [
      { required: true, message: '部门编号不能为空' },
      { min: 3, max: 8, message: '长度不能小于3，大于12' },
      { pattern: regs.alphanum, message: '部门编号必须是数字或者字母' },
    ],
  },
  {
    name: 'Name',
    type: 'text',
    label: '部门名称',
    grid: 12 / 24,
    rules: [
      { required: true, message: '部门名称不能为空' },
      { min: 3, max: 30, message: '长度不能小于3，大于30' },
    ],
  },
  {
    name: 'ParentID',
    label: '所属部门',
    type: 'tree-select',
    grid: 12 / 24,
    dataType: 'number',
    fetch: {
      tableName: 'Organization',
      optionTpl: 'Name',
      valueTpl: 'ID',
      parentTpl: 'ParentID',
      isDao: true,
    },
    rules: [{ required: true, message: '所属部门不能为空' }],
  },
  {
    name: 'TypeID',
    label: '部门类型',
    type: 'select',
    grid: 12 / 24,
    dataType: 'number',
    fetch: { tableName: 'OrganizationType', optionTpl: 'Name', valueTpl: 'ID', isDao: true },
    rules: [{ required: true, message: '部门类型不能为空' }],
  },
  {
    name: 'OrderNo',
    type: 'number',
    label: '顺序号',
    grid: 12 / 24,
    dataType: 'number',
    rules: [{ required: true, message: '顺序号不能为空' }],
  },
];
const order: API.OrderItem = { FieldName: 'OrderNo', Direction: 'ASC' };
const Organizations: React.FC = () => {
  return (
    <CommonPage
      daoName={daoName}
      columns={columns}
      controls={controls}
      initSorter={order}
      title="部门信息"
    />
  );
};

export default Organizations;
